package main

import "fmt"

type Custom struct {
	i int
}

var carr [5]*Custom = [5]*Custom{
	{6},
	{7},
	{8},
	{9},
	{10},
}

func main() {
	// 1 仅声明
	//var a [5]int
	//fmt.Println("a = ", a)
	//
	//var marr [2]map[string]string
	//fmt.Println("marr = ", marr)
	// map的零值是nil，虽然打印出来是非空值，但真实的值是nil
	// marr[0]["test"] = "1"

	// 2 声明以及初始化
	//var b [5]int = [5]int{1, 2, 3, 4, 5}
	//fmt.Println("b = ", b)

	// 类型推导声明方式
	//var c = [5]string{"c1", "c2", "c3", "c4", "c5"}
	//fmt.Println("c = ", c)
	//
	//d := [3]int{3, 2, 1}
	//fmt.Println("d = ", d)

	// 使用 ... 代替数组长度
	//autoLen := [...]string{"auto1", "auto2", "auto3", "auto3"}
	//fmt.Println("autoLen = ", autoLen)

	// 声明时初始化指定下标的元素值
	//positionInit := [5]string{1: "position1", 3: "position3"}
	//fmt.Println("positionInit = ", positionInit)

	// 初始化时，元素个数不能超过数组声明的长度
	//overLen := [2]int{1, 2, 3}

	// 二维数组
	//a := [3][2]int{
	//	{0, 1},
	//	{2, 3},
	//	{4, 5},
	//}
	//fmt.Println("a = ", a)

	// 三维数组
	//b := [3][2][2]int{
	//	{{0, 1}, {2, 3}},
	//	{{4, 5}, {6, 7}},
	//	{{8, 9}, {10, 11}},
	//}
	//fmt.Println("b = ", b)
	//
	//// 也可以省略各个位置的初始化,在后续代码中赋值
	//c := [3][3][3]int{}
	//c[2][2][1] = 5
	//c[1][2][1] = 4
	//fmt.Println("c = ", c)

	a := [5]int{5, 4, 3, 2, 1}
	fmt.Println("before all, a = ", a)
	for i := range carr {
		fmt.Printf("in main func, carr[%d] = %p, value = %v \n", i, &carr[i], *carr[i])
	}
}

func receiveArray(param [5]int) {
	fmt.Println("in receiveArray func, before modify, param = ", param)
	param[1] = -5
	fmt.Println("in receiveArray func, after modify, param = ", param)
}

func receiveArrayPointer(param *[5]int) {
	fmt.Println("in receiveArrayPointer func, before modify, param = ", param)
	param[1] = -5
	fmt.Println("in receiveArrayPointer func, after modify, param = ", param)
}

func printFuncParamPointer(param [5]*Custom) {
	for i := range param {
		fmt.Printf("in printFuncParamPointer func, param[%d] = %p, value = %v \n", i, &param[i], *param[i])
	}
}
